package test;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateUtils;
import org.junit.Test;

import java.util.Calendar;
import java.util.Date;

/**
 * org.apache.commons.lang3.time.DateUtils 的用法
 * java.util.DateUtils 的用法
 * Calendar 的
 * Date 的
 * 
 * @author Liu Huan
 */
@Slf4j
public class DateAndTimestamp {
    @Test
    public void testStartEnd(){
        System.out.println("startDate = " + new Date(1610553600000L));
        System.out.println("engDate   = " + new Date(1610640000000L));
    }
    
    /**
     * Date 日期 常用方法
     * getTime() 返回 long 值，自 1970 年 1 月 1 日 00:00:00 GMT 的毫秒值
     * setTime()
     */
    @Test
    public void testDate(){// data 数据 date 日期
        Date startDate = new Date();
        System.out.println(startDate);
        System.out.println(startDate.toString());
        System.out.println(startDate.getTime());
        
        startDate.setTime(1610380800515L);
        System.out.println(startDate);
        Date start = new Date(1610467200515L);
        System.out.println(start);
    }
    
    @Test
    public void testCalendar(){
        Calendar calendar = Calendar.getInstance();
        
    }
    
    @Test
    public void testAddXxx(){
        Date curDate = new Date();
        System.out.println(curDate);
        
        Date startDate = new Date();
        startDate = DateUtils.addDays(curDate, +1);
        System.out.println(startDate);
        startDate = DateUtils.addDays(curDate, -1);
        System.out.println(startDate);
        curDate = DateUtils.addHours(curDate, -2);
        System.out.println(curDate);
    }
    
    @Test
    public void test(){
        Date firstSeconds = DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH);
        Date startDate = DateUtils.addDays(firstSeconds, -2);
        Date endDate = DateUtils.addDays(firstSeconds, -1);
//        endDate.setTime(endDate.getTime()-1);
        System.out.println(startDate);
        System.out.println(startDate.getTime());
        System.out.println(endDate);
        System.out.println(endDate.getTime());
    }
    
    @Test
    public void testDateToTimestamp(){
        Date date = new Date();
        Long timestamp = date.getTime();
        System.out.println(date);
        System.out.println(timestamp);
    }
}
